<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>게시판 글쓰기</title>

<script src="/Jangdolbaeng2/js/jquery-1.11.1.js" type="text/javascript"></script>
<s:if test="insertResult !=null && insertResult !=0">
<script type="text/javascript">
// 입력에 성공하면 창닫기
	opener.location.href="seller/blogMain.action?shop_seq=${session.current_shop_seq}";
	window.close();
</script>
</s:if>
</head>
<body>
	<s:form id="writeform" action="boardWrite" method="post"
		enctype="multipart/form-data" onsubmit="return titleTest();"
		theme="simple">

		<table border=0 cellpadding=3>
			<tr>
				<td colspan=2 align=center><h2>[ 글쓰기 ]</h2></td>
			</tr>
			<tr>
				<td>제목</td>
				<td><s:textfield name="shop_qa.qa_title" id="qa_title"
						cssStyle="width:400px;" onblur="formCheck()" /></td>
			</tr>
			<tr>
				<td>내용</td>
				<td><s:textarea name="shop_qa.qa_contents" id="qa_contents"
						cssStyle="width:400px;height:200px;resize:none;"></s:textarea></td>
			</tr>
			<tr>
				<td colspan="2" align=center><s:submit value="저장"
						id="formSubmit" disabled='false' /></td>
			</tr>
		</table>
	</s:form>
	<div id="test"></div>
	<script type="text/javascript">
//글쓰기폼 확인
function formCheck() {		
		$.ajax({
		type:"post",
		url:"spamCheck.action",		
		data:{searchText : $('#qa_title').val()},
		success:function(json){
			if(json.spamCheck != 0){				
				alert("해당 제목에 금칙어가 포함되어 있습니다.");
				$('#formSubmit').attr('disabled',true);
			}
			else if(json.spamCheck == 0){				
				$('#formSubmit').attr('disabled',false);
				
			}
		}});
}

// 작성글 양식 확인	
function titleTest(){
	var title = document.getElementById('qa_title');
	var content = document.getElementById('qa_contents');
	
	if (title.value.length < 5) {
		alert("제목을 5자 이상 입력하세요.");
		title.focus();
		title.select();
		return false;
	}
	
	if (content.value.length < 10) {
		alert("내용을 10자 이상 입력하세요.");
		title.focus();
		title.select();
		return false;
	}		
	return true;	
}
 
</script>
</body>
</html>
